package com.angel.core.util;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

public class JsonResult {
	public static void failResult(HttpServletResponse response, String msg)
	  {
	    Map<String, Object> map = new HashMap();
	    map.put("success", Boolean.valueOf(false));
	    map.put("msg", msg);
	    sendResult(response, JsonUtils.toJson(map));
	  }
	  
	  public static void successResult(HttpServletResponse response, String msg)
	  {
	    Map<String, Object> map = new HashMap();
	    map.put("success", Boolean.valueOf(true));
	    map.put("msg", msg);
	    sendResult(response, JsonUtils.toJson(map));
	  }
	  
	  public static void sendResult(HttpServletResponse response, String result)
	  {
	    try
	    {
	      response.setCharacterEncoding("utf-8");
	      response.setContentType("application/json;charset=utf-8");
	      response.setHeader("Pragma", "No-cache");
	      response.setHeader("Cache-Control", "no-cache");
	      response.setDateHeader("Expires", 0L);
	      response.getWriter().write(result);
	      response.getWriter().flush();
	    }
	    catch (Exception ex)
	    {
	      ex.printStackTrace();
	    }
	  }
}
